<template>
  <el-cascader
    :options="selectData"
    :props="props"
    separator="-"
    size="mini"
    :value="value"
    @change="deliverID"
  />
</template>

<script>
import { departmentDataAPI } from '@/api/department'
import { listToTreeList } from '@/utils/index'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      selectData: [],
      props: {
        value: 'id',
        label: 'name'
      }
    }
  },
  created() {
    this.selectTreeData()
  },
  methods: {
    async selectTreeData() {
      this.selectData = listToTreeList(await departmentDataAPI(), 0)
    },
    deliverID(params) {
      if (params.length > 0) {
        this.$emit('input', params[params.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style>

</style>
